import 'package:flutter/material.dart';

/// 中间插入文本的分割线
class TagDivider extends StatelessWidget {
  final String text;
  final BorderStyle lineStyle;
  final double thickness;
  final AlignmentGeometry textAlign;
  final double padding;
  final double vPadding;
  final Color background;
  final Color color;
  final Color? textColor;
  final double? dividerWidth;
  final void Function()? onTap;

  const TagDivider(
    this.text, {
    Key? key,
    this.lineStyle = BorderStyle.solid,
    this.textAlign = Alignment.center,
    this.padding = 20,
    this.vPadding = 10,
    this.background = Colors.transparent,
    this.color = Colors.black38,
    this.onTap,
    this.thickness = 0.5,
    this.textColor,
    this.dividerWidth,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(vertical: padding, horizontal: vPadding),
        color: background,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (textAlign != Alignment.centerLeft)
              dividerWidth == null
                  ? Expanded(
                      child: Divider(
                        thickness: thickness,
                        color: color,
                      ),
                    )
                  : SizedBox(
                      width: dividerWidth,
                      child: Divider(
                        thickness: thickness,
                        color: color,
                      ),
                    ),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 10),
              child: Text(
                text,
                style: TextStyle(color: textColor ?? color, fontSize: 12),
              ),
            ),
            if (textAlign != Alignment.centerRight)
              dividerWidth == null
                  ? Expanded(
                      child: Divider(
                        thickness: thickness,
                        color: color,
                      ),
                    )
                  : SizedBox(
                      width: dividerWidth,
                      child: Divider(
                        thickness: thickness,
                        color: color,
                      ),
                    ),
          ],
        ),
      ),
    );
  }
}
